﻿using System;
using System.Web.UI;
using BLL;

public partial class ProductAging_QualAging_InBoxQual : System.Web.UI.Page
{
    private Aging ag;
    private string agingID
    {
        get
        {
            return ViewState["AgingID"].ToString();
        }
        set
        {
            ViewState["AgingID"] = value;
        }
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (Request.QueryString["AgingID"] != null)
            {
                agingID = Request.QueryString["AgingID"];
                this.TextBox1.Text = agingID;
                BindAging(agingID);
            }
        }
    }

    public ProductAging_QualAging_InBoxQual()
    {
        ag = new Aging();
    }

    protected void Button1_Click(object sender, EventArgs e)
    {
        agingID = this.TextBox1.Text.Trim();
        if (!ag.Aging_ExistsValidID(agingID))
        {
            string str1 = "此批次号不存在，或者没有相关的进箱信息，请确认！";
            ScriptManager.RegisterStartupScript(this.UpdatePanel1, this.GetType(), "click", "<script>alert('" + str1 + "');</script>", false);
        }
        else
        {
            BindAging(agingID);
        }
    }

    protected void BindAging(string agingID)
    {
        UserControl_Aging uc = (UserControl_Aging)LoadControl("~/UserControl/Aging.ascx");
        uc.agingID = agingID;
        this.PlaceHolder1.Controls.Add(uc);
    }

    protected void Button2_Click(object sender, EventArgs e)
    {
        try
        {
            int amount = int.Parse(this.TextBox2.Text.Trim());
            string userID = User.Identity.Name;
            string str = ag.Aging_InBoxQual(agingID, userID, amount);
            ScriptManager.RegisterStartupScript(this.UpdatePanel1, this.GetType(), "click", "<script>alert('" + str + "');</script>", false);
            BindAging(agingID);
        }
        catch (FormatException)
        {
            string str1 = "输入确认数量的格式不对！";
            ScriptManager.RegisterStartupScript(this.UpdatePanel1, this.GetType(), "click", "<script>alert('" + str1 + "');</script>", false);
        }
    }
}
